/*     */ package com.qmsk.business.info.integralcoupon.controller;
/*     */ 
/*     */ import com.qmsk.business.bussBill.pbPaid.PbPaid;
/*     */ import com.qmsk.business.info.integralcoupon.dao.IntegralCouponDao;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/intCoupon"})
/*     */ public class IntegralCouponController
/*     */ {
/*  29 */   private static final Logger logger = Logger.getLogger(IntegralCouponController.class);
/*     */ 
/*     */   @Autowired
/*     */   private IntegralCouponDao dao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  55 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  57 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/*  58 */         nPageSize);
/*  59 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  61 */       logger.error(e);
/*  62 */       ResponseUtils.setErrorMsgResponse(
/*  63 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/stId/{shopId}/{stId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getIntegralCash(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("stId") Integer stId)
/*     */   {
/*     */     try
/*     */     {
/*  82 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopIdAndStId(shopId, stId);
/*  83 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  85 */       logger.error(e);
/*  86 */       ResponseUtils.setErrorMsgResponse(
/*  87 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/intAmtDisct/{st}/{memberId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getCashOfIntegralSt(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Object shopId, @PathVariable("st") String st, @PathVariable("memberId") Object memberId)
/*     */   {
/*     */     try
/*     */     {
/*  98 */       int stId = PbPaid.getStOfId(st);
/*  99 */       GsonEbRst gsonEbRst = this.dao.getCouPonOfIntegralRatio(shopId, stId, 
/* 100 */         memberId);
/* 101 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 103 */       logger.error(e);
/* 104 */       ResponseUtils.setErrorMsgResponse(
/* 105 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/groupCode/{shopId}/{groupCode}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getIntegralCashOfGroupCode(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("groupCode") Integer groupCode)
/*     */   {
/*     */     try
/*     */     {
/* 124 */       GsonEbRst gsonEbRst = this.dao.getIntegralCashOfGroupCode(groupCode, 
/* 125 */         shopId);
/* 126 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 128 */       logger.error(e);
/* 129 */       ResponseUtils.setErrorMsgResponse(
/* 130 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 146 */     String sGsonInData = RequestUtils.getString(request, "data");
/*     */     try {
/* 148 */       GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sGsonInData);
/* 149 */       if (g != null) {
/* 150 */         Object stId = g.getValueOfName("stID");
/* 151 */         Object shopId = g.getValueOfName("shopId");
/* 152 */         Object ruleType = g.getValueOfName("ruleType");
/* 153 */         Object levelId = g.getValueOfName("levelId");
/* 154 */         if (this.dao.isExistsStIdRuleType(stId, shopId, ruleType, levelId).longValue() <= 0L)
/*     */         {
/* 156 */           int nResult = this.dao.insertGsonHeadOneRow(g);
/* 157 */           DbConnection.commit();
/* 158 */           ResponseUtils.setSqlResultResponse(nResult, 
/* 159 */             RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 160 */             response);
/* 161 */           return; }
/* 162 */         ResponseUtils.setErrorMsgResponse("服务类型或规则类别已使用，请重新选择", 
/* 163 */           response);
/*     */ 
/* 165 */         return; }
/* 166 */       ResponseUtils.setErrorMsgResponse(
/* 167 */         RequestUtils.getReadJsonDataErrorMessage(request), 
/* 168 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 171 */       DbConnection.rollback();
/* 172 */       logger.error(e);
/* 173 */       ResponseUtils.setErrorMsgResponse(
/* 174 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 175 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 188 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 190 */       String[] strParams = id.split(",");
/* 191 */       int nResult = this.dao.deleteParams(strParams);
/* 192 */       DbConnection.commit();
/* 193 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 194 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 195 */         response);
/*     */     } catch (Exception e) {
/* 197 */       DbConnection.rollback();
/* 198 */       logger.error(e);
/* 199 */       ResponseUtils.setErrorMsgResponse(
/* 200 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 201 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 218 */     String id = request.getParameter("id");
/* 219 */     String sGsonInData = request.getParameter("data");
/*     */     try {
/* 221 */       GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sGsonInData);
/* 222 */       if (g == null) {
/* 223 */         ResponseUtils.setErrorMsgResponse(
/* 224 */           RequestUtils.getReadJsonDataErrorMessage(request), 
/* 225 */           response);
/* 226 */         return; }
/* 227 */       int nResult = 0;
/* 228 */       if ((id == null) || (id == "")) {
/* 229 */         ResponseUtils.setErrorMsgResponse("获取Id信息失败", response);
/* 230 */         return; }
/* 231 */       if ((g.getValueOfName("ruleType") != null) || 
/* 232 */         (g.getValueOfName("stID") != null) || 
/* 233 */         (g.getValueOfName("levelId") != null)) {
/* 234 */         Object stId = null;
/* 235 */         Object ruleType = null;
/* 236 */         Object levelId = null;
/* 237 */         GsonHeadOneRow r = this.dao.getIntegralCashOfId(id);
/* 238 */         if (g.getValueOfName("stID") != null)
/* 239 */           stId = g.getValueOfName("stID");
/*     */         else {
/* 241 */           stId = r.getValueOfName("stID");
/*     */         }
/*     */ 
/* 244 */         if (g.getValueOfName("ruleType") != null)
/* 245 */           ruleType = g.getValueOfName("ruleType");
/*     */         else {
/* 247 */           ruleType = r.getValueOfName("ruleType");
/*     */         }
/*     */ 
/* 250 */         if (g.getValueOfName("levelId") != null)
/* 251 */           levelId = g.getValueOfName("levelId");
/*     */         else {
/* 253 */           levelId = r.getValueOfName("levelId");
/*     */         }
/* 255 */         Object shopId = r.getValueOfName("shopID");
/* 256 */         nResult = this.dao.isExistsStIdRuleType_update(stId, shopId, 
/* 257 */           ruleType, levelId).intValue();
/* 258 */         if (nResult > 0) {
/* 259 */           ResponseUtils.setErrorMsgResponse(
/* 260 */             "服务类型或规则类别已使用，请重新选择", response);
/* 261 */           return;
/*     */         }
/*     */       }
/* 264 */       nResult += this.dao.updateJsonOneRow(g, id);
/* 265 */       if (nResult > 0)
/* 266 */         DbConnection.commit();
/*     */       else {
/* 268 */         DbConnection.rollback();
/*     */       }
/* 270 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 271 */         RequestUtils.getSqlUpdateErrorMessage(sGsonInData, request), 
/* 272 */         response);
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 276 */       DbConnection.rollback();
/* 277 */       logger.error(e);
/* 278 */       ResponseUtils.setErrorMsgResponse(
/* 279 */         RequestUtils.getSqlUpdateErrorMessage(sGsonInData, request) + 
/* 280 */         ":" + e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.info.integralcoupon.controller.IntegralCouponController
 * JD-Core Version:    0.5.3
 */